<?php
/**
* Settings manager.
*
* Copyright (c) 2009 James Gauld <james@jamesgauld.net>
* This file is part of Scribble.
* @license http://www.scribblecms.co.uk/license.txt
*
* @package Scribble
*/
use Buan\Config;
use Buan\SystemLog;
class SettingsController extends ScribbleAdminController {

	/**
	* Main configuration interface.
	*
	* @param array Action parameters (none supported)
	* @return ScribbleAdminView
	*/
	public function index($params) {

		// Init
		$view = new ScribbleAdminView();
		if(!$this->init($view)) {
			return $view;
		}
		$view->setSource(Config::get('ext.Scribble.dir.views').'/scribble/settings/index.tpl.php');

		// Save settings
		if(!empty($_POST)) {

			// Gather
			$setting = (object)array(
				'maintenanceMode'=>isset($_POST['maintenanceMode']) ? (int)$_POST['maintenanceMode'] : 0
			);

			// Validate

			// Save
			ScribbleRegistry::set('ext.Scribble.maintenanceMode', $setting->maintenanceMode);
			SystemLog::add('Settings have been saved.', SystemLog::INFO);
		}

		// Load current settings
		$view->setting = (array)ScribbleRegistry::get('ext.Scribble');

		// Result
		return $view;
	}
}
?>